package com.fxw.config;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @ClassName DataSourceAop
 * @Deacription TODO
 * @Author hqq
 * @Date 2021/10/25 22:20
 * @Version 1.0
 **/
@Aspect //切面类
@Component
public class DataSourceAop {

   /* @Pointcut("!@annotation(com.dk.config.annotation.master) " +
            "&& (execution(* com.dk.service..*.select*(..)) " +
            "|| execution(* com.dk.service..*.get*(..)))")
    public void readPointcut() {

    }

    @Pointcut("@annotation(com.dk.config.annotation.master) " +
            "|| execution(* com.dk.service..*.insert*(..)) " +
            "|| execution(* com.dk.service..*.add*(..)) " +
            "|| execution(* com.dk.service..*.update*(..)) " +
            "|| execution(* com.dk.service..*.delete*(..)) " +
            "|| execution(* com.dk.service..*.remove*(..))")
    public void writePointcut() {

    }

    @Before("readPointcut()")
    public void read() {
        DBContextHolder.slave();
    }

    @Before("writePointcut()")
    public void write() {
        DBContextHolder.master();
    }*/

   @Before("@annotation(com.fxw.annotation.ReadDataSouce)")
   public void readPoint(){
       System.out.println("进入了从库");
       DBContextHolder.setDataBaseSlave();
   }

   @Before("@annotation(com.fxw.annotation.MasterDataSource)")
   public void writePoint(){
       System.out.println("进入了主库");
       DBContextHolder.setDataBaseMaster();
   }
}
